package com.qvtu.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qvtu.web.VO.booksVo;
import com.qvtu.web.VO.userVo;
import com.qvtu.web.domain.Books;
import com.qvtu.web.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class HomeController {
    @Autowired
    private IBooksService booksService;
    @Autowired
    private IPublisherService publisherService;
    @Autowired
    private IBookStatusService bookStatusService;
    @Autowired
    private IBookCategroyService bookCategroyService;
    @Autowired
    private IUsersService usersService;
    @RequestMapping("/books")
    public String home(@RequestParam(defaultValue = "1") Integer pageNum, Model model){
//        System.out.println(booksService.SelectBooksDetail());
//        PageHelper.startPage(pageNum,2);

        PageHelper.startPage(pageNum,5);
        List<booksVo> booksList1=booksService.SelectBooksDetail();
        PageInfo<booksVo> bookPage=new PageInfo<>(booksList1);
        model.addAttribute("bookPage",bookPage);

        List publisherList =publisherService.list();
        model.addAttribute("publisherList",publisherList);

        List statusList =bookStatusService.list();
        model.addAttribute("statusList",statusList);

        List categroyList =bookCategroyService.list();
        model.addAttribute("categroyList",categroyList);

        return  "MainInterface/books";
    }
    @RequestMapping("/publisher")
    public  String publisher( Model model)
    {
        List publisherList =publisherService.list();
        model.addAttribute("publisherList",publisherList);
        return  "MainInterface/publisher";
    }

    @RequestMapping("/bookStatus")
    public  String bookStatus(Model model)
    {
        List statusList =bookStatusService.list();
        model.addAttribute("statusList",statusList);
        return  "MainInterface/bookStatus";
    }

    @RequestMapping("/bookCategroy")
    public  String bookCategroy(Model model)
    {
        List categroyList =bookCategroyService.list();
        model.addAttribute("categroyList",categroyList);
        return  "MainInterface/bookCategroy";
    }
    @RequestMapping("/userManage")
    public String userManage(@RequestParam(defaultValue = "1") Integer pageNum, Model model){

        PageHelper.startPage(pageNum,5);
        List<userVo> userList=usersService.userBooksDetail();
        PageInfo<userVo> usersPage=new PageInfo<>(userList);
        model.addAttribute("usersPage",usersPage);
        return  "MainInterface/userManage";
    }
}
